﻿Imports SpatialAlbum.VirtualEarthMap

Partial Public Class MapViewControl
    Implements IMapControl

    Public Event PhotoClicked(ByVal VE_shapeid As String, ByVal row As DataRow) Implements IMapControl.PhotoClicked
    Public Event PhotoDoubleClicked(ByVal VE_shapeid As String, ByVal row As DataRow) Implements IMapControl.PhotoDoubleClicked
    Public Event WebpageError(ByVal message As String, ByVal url As String, ByVal line As Integer) Implements IMapControl.WebpageError
    Public Event LoadingWebpage() Implements IMapControl.LoadingWebpage
    Public Event LoadingPhotos() Implements IMapControl.LoadingPhotos
    Public Event LoadComplete() Implements IMapControl.LoadComplete

#Region " IMapControl properties "
    Public WriteOnly Property AlbumManager() As AlbumManager Implements IMapControl.AlbumManager
        Set(ByVal value As Core.AlbumManager)
            VirtualEarthMapControl1.AlbumManager = value
        End Set
    End Property

    Public WriteOnly Property Connection() As Connection Implements IMapControl.Connection
        Set(ByVal value As Core.Connection)
            VirtualEarthMapControl1.Connection = value
        End Set
    End Property
    Public Property ShowControlsOnMap() As Boolean Implements IMapControl.ShowControlsOnMap
        Get
            Return VirtualEarthMapControl1.ShowControlsOnMap
        End Get
        Set(ByVal value As Boolean)
            VirtualEarthMapControl1.ShowControlsOnMap = value
        End Set
    End Property
    Public WriteOnly Property AutoResize() As Boolean Implements IMapControl.AutoResize
        Set(ByVal value As Boolean)
            VirtualEarthMapControl1.AutoResize = value
        End Set
    End Property
#End Region

    Public Shared ReadOnly AutoResizeMapProperty As DependencyProperty = _
        DependencyProperty.Register( _
            "AutoResizeMap", _
            GetType(Boolean), _
            GetType(MapViewControl), _
            New PropertyMetadata(True, New PropertyChangedCallback(AddressOf OnAutoResizeMapPropertyChanged)))

    Public Property AutoResizeMap() As Boolean
        Get
            Return GetValue(AutoResizeMapProperty)
        End Get
        Set(ByVal value As Boolean)
            SetValue(AutoResizeMapProperty, value)
        End Set
    End Property

    Public Sub PanTo(ByVal latitude As Double, ByVal longitude As Double)
        VirtualEarthMapControl1.PanTo(latitude, longitude)
    End Sub

    Protected Overrides Function ArrangeOverride(ByVal finalSize As System.Windows.Size) As System.Windows.Size
        Return MyBase.ArrangeOverride(finalSize)
    End Function

    Protected Overrides Function MeasureOverride(ByVal availableSize As System.Windows.Size) As System.Windows.Size
        ' let the system handle this...
        If Double.IsInfinity(availableSize.Width) Then Return MyBase.MeasureOverride(availableSize)

        VirtualEarthMapControl1.SetSize(availableSize.Width, availableSize.Height)
        Return availableSize
    End Function

    Public Shared Sub OnAutoResizeMapPropertyChanged(ByVal d As DependencyObject, ByVal e As DependencyPropertyChangedEventArgs)
        Dim mvc As MapViewControl = CType(d, MapViewControl)
        mvc.AutoResize = e.NewValue
    End Sub

    Private Sub VirtualEarthMapControl1_LoadComplete() Handles VirtualEarthMapControl1.LoadComplete
        RaiseEvent LoadComplete()
    End Sub

    Private Sub VirtualEarthMapControl1_LoadingPhotos() Handles VirtualEarthMapControl1.LoadingPhotos
        RaiseEvent LoadingPhotos()
    End Sub

    Private Sub VirtualEarthMapControl1_LoadingWebpage() Handles VirtualEarthMapControl1.LoadingWebpage
        RaiseEvent LoadingWebpage()
    End Sub

    Private Sub VirtualEarthMapControl1_PhotoClicked(ByVal VE_shapeid As String, ByVal row As System.Data.DataRow) Handles VirtualEarthMapControl1.PhotoClicked
        RaiseEvent PhotoClicked(VE_shapeid, row)
    End Sub

    Private Sub VirtualEarthMapControl1_PhotoDoubleClicked(ByVal VE_shapeid As String, ByVal row As System.Data.DataRow) Handles VirtualEarthMapControl1.PhotoDoubleClicked
        RaiseEvent PhotoDoubleClicked(VE_shapeid, row)
    End Sub

    Private Sub VirtualEarthMapControl1_WebpageError(ByVal message As String, ByVal url As String, ByVal line As Integer) Handles VirtualEarthMapControl1.WebpageError
        RaiseEvent WebpageError(message, url, line)
    End Sub
End Class
